package com.example.yingjiguanli_demo.mapper;

import com.example.yingjiguanli_demo.pojo.Leaderboard;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author scj
 * @since 2024-11-15
 */
@Mapper
public interface LeaderboardMapper extends BaseMapper<Leaderboard> {
    @Select("SELECT * FROM leaderboard WHERE user_id = #{userId}")
    Leaderboard selectById(@Param("userId") Integer userId);

    // 自定义方法，用于更新记录
    @Update("UPDATE leaderboard SET total_score = #{leaderboard.totalScore}, " +
            "win_count = #{leaderboard.winCount}, " +
            "lose_count = #{leaderboard.loseCount}, " +
            "draw_count = #{leaderboard.drawCount}, " +
            "last_updated = #{leaderboard.lastUpdated} " +
            "WHERE user_id = #{leaderboard.userId}")
    void update(@Param("leaderboard") Leaderboard leaderboard);
}
